<template>
  <a-card>
    <div :class="advanced ? 'search' : null">
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row >
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="规则编号"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-input placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="使用状态"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-select placeholder="请选择">
                <a-select-option value="1">关闭</a-select-option>
                <a-select-option value="2">运行中</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        </div>
        <span style="float: right; margin-top: 3px;">
          <a-button type="primary">查询</a-button>
          <a-button style="margin-left: 8px">重置</a-button>
          <a @click="toggleAdvanced" style="margin-left: 8px">
            {{advanced ? '收起' : '展开'}}
            <a-icon :type="advanced ? 'up' : 'down'" />
          </a>
        </span>
      </a-form>
    </div>
    <div>
      <a-space class="operator">
        <a-button @click="$refs.createForm.handleAdd()" type="primary">新增</a-button>
        <a-dropdown>
          <a-menu @click="handleMenuClick" slot="overlay">
            <a-menu-item key="audit">审批</a-menu-item>
          </a-menu>
          <a-button>
            更多操作 <a-icon type="down" />
          </a-button>
        </a-dropdown>
      </a-space>

         <!-- 增加修改 -->
        <create-form
        ref="createForm"
        :gunTypeOptions="gunTypeOptions"
        @ok="getList"
      />

      <standard-table
        :columns="columns"
        :dataSource="brandList"
        :rowKey="(record,index)=>{return index}"
        :selectedRows.sync="selectedRows"
        :bordered="true"
        @clear="onClear"
        @change="onChange"
        @selectedRowChange="onSelectChange"
      >
      
        <div slot="action" slot-scope="{ record}">
          <a style="margin-right: 8px" @click="$refs.createForm.handleUpdate(record, undefined)">
            <a-icon type="edit"/>编辑
          </a>
          <a @click="playRecord(record.resourceUrl)">
            <a-icon type="play-circle" />播放</a>
        </div>

        <div slot="cover" slot-scope="{ record}">
          <a-avatar slot="avatar" size="large" shape="square" :src="record.coverUrl"/>
        </div>
        <template slot="statusTitle">
          <a-icon @click.native="onStatusTitleClick" type="info-circle" />
        </template>
      </standard-table>
    </div>
    <template>
      <div>
        <a-modal v-model="visible" title="Basic Modal" @ok="handleOk">
          <video-player class="video-player vjs-custom-skin" 
                      ref="videoPlayer" 
                      :playsinline="true" 
                      :options="playerOptions">
        </video-player>
        </a-modal>
      </div>
    </template>
    
  </a-card>
  
</template>

<script>
import { videoPlayer } from 'vue-video-player';
import 'video.js/dist/video-js.css';
import StandardTable from '@/components/table/StandardTable';
import { listMovie } from "@/services/movie";
import CreateForm from "./modules/CreateForm"
const columns = [
  {
    title: '电影名称',
    dataIndex: 'name',
  },
  {
    title: '封面',
    dataIndex: 'coverUrl',
    scopedSlots: { customRender: 'cover' }
  },
  {
    title: '分类',
    dataIndex: 'classify',
    needTotal: true,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    sorter: true
  },
  {
    title: '操作',
    scopedSlots: { customRender: 'action' }
  }
]

const dataSource = []

export default {
  name: 'MovieList',
  components: {StandardTable,videoPlayer,CreateForm},
  data () {
    return {
      advanced: true,
      columns: columns,
      dataSource: dataSource,
      brandList: [],
      selectedRows: [],
      visible: false,
      addVisible:false,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form:{
        name:'www',
      },
      queryParams: {
      },
      playerOptions: {
                playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
                autoplay: false,  // 如果为true,浏览器准备好时开始回放
                muted: false,     // 默认情况下将会消除任何音频。
                loop: false,      // 是否视频一结束就重新开始。
                preload: 'auto',  // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
                language: 'zh-CN',
                aspectRatio: '16:9',  // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
                fluid: true,  // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
                sources: [{
                    type: "video/mp4",  // 类型
                    src: ''             // url地址
                }],
                poster: '',  // 封面地址
                notSupportedMessage: '此视频暂无法播放，请稍后再试',  // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
                controlBar: {
                    timeDivider: true,           // 当前时间和持续时间的分隔符
                    durationDisplay: true,       // 显示持续时间
                    remainingTimeDisplay: false, // 是否显示剩余时间功能
                    fullscreenToggle: true       // 是否显示全屏按钮
                }
      }
    }
  },
  authorize: {
    deleteRecord: 'delete'
  },
  created(){
    this.getList();
  },
  methods: {

     getList() {
    
      listMovie(this.queryParams).then(response => {
        console.log("获取到电影的啦",response.data);
        this.brandList =  response.data.rows;
      });
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },

    playRecord(key) {
      console.log("这不就点击播放啦！！",key);
      this.playerOptions.sources[0].src = key;
      this.visible = true;
      
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
      this.selectedRows = []
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    onSelectChange() {
      this.$message.info('选中行改变了')
    },
    addNew () {
      this.addVisible = true;
    },
    handleMenuClick (e) {
      if (e.key === 'delete') {
        this.remove()
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .search{
    margin-bottom: 54px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
